import { Label, Node } from "cc"
import { ccclass, EUILayer, EBlockOnceAdType, _scene, _platform, EPlatformType, EBottomAdType, _ui, _rank, _logic, _gameType, SwitchSpriteCC } from "../Main"
import { AnimBaseUI } from "./AnimBaseUI"
import { EGameType } from "../module/define/GameTypeDefine"
import { initData, isCouShi } from "../../../app/GameDefine"


@ccclass("IndexUI")
export class IndexUI extends AnimBaseUI {
	public layerType = EUILayer.WindowUp
	public blockOnceAdType = EBlockOnceAdType.Show
	public bottomAdType = EBottomAdType.None

	private cSwitchSpriteCCLogo: SwitchSpriteCC = null!
	private cBsidebar: Node = null!

	protected onCreate(): void {
		super.onCreate()

		switch (_platform.type) {
			case EPlatformType.tt:
				this.cSwitchSpriteCCLogo.index = 2
				break;
			case EPlatformType.vivo:
				this.cSwitchSpriteCCLogo.index = 3
				break;

			default:
				if (isCouShi){
					this.cSwitchSpriteCCLogo.index = 1
				}
				else{
					this.cSwitchSpriteCCLogo.index = 0
				}
				break;
		}

		this.updateSidebar()
		this.cSwitchSpriteCCLogo.index = 3
	}

	protected onOpen(): void {
		super.onOpen()
	}

	private updateSidebar() {
		if (_platform.type == EPlatformType.tt) {
			this.cBsidebar.active = _platform._tt.sidebar.isEnable
		}
		else
			this.cBsidebar.active = false
	}

	private onClickBsidebar() {
		_ui.open(initData.uiUrl.sidebar)
	}

	private onClickBnuoToday() {
		this.clickRunType(EGameType.nuoToday)
	}

	private onClickBten() {
		this.clickRunType(EGameType.tenLevel)
	}

	private onClickBlevel() {
		this.clickRunType(EGameType.nuoLevel)
	}

	private clickRunType(type: EGameType) {
		if (_gameType.hasRun(type))
			this.playAnim(false, () => {
				if (!_gameType)
					return
				if (!this.scene) {
					_gameType.type = type
					_ui.Loading.wait(true)
					return
				}

				_gameType.run(type)
			})
	}

}
